package pro.shushi.pamirs.hr.api.model.org;

import pro.shushi.pamirs.boot.base.ux.annotation.field.UxWidget;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxDetail;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxForm;
import pro.shushi.pamirs.boot.base.ux.annotation.view.UxTableSearch;
import pro.shushi.pamirs.hr.api.enums.SimpleGenderEnum;
import pro.shushi.pamirs.hr.api.enums.EmployeeLevelEnum;
import pro.shushi.pamirs.hr.api.enums.HrEmployeeStatusEnum;
import pro.shushi.pamirs.meta.annotation.Field;
import pro.shushi.pamirs.meta.annotation.Model;
import pro.shushi.pamirs.meta.base.IdModel;
import pro.shushi.pamirs.meta.enmu.DateFormatEnum;
import pro.shushi.pamirs.meta.enmu.DateTypeEnum;
import pro.shushi.pamirs.resource.api.model.ResourceDistrict;

import java.util.Date;
import java.util.List;

import static pro.shushi.pamirs.meta.annotation.Field.serialize.COMMA;

// 模型中UX开头的注解(UxForm/UxTable/UxDetail等)可以不用写，都可在设计器中进行可视化配置; 代码里面写这些注解是为了默认页面的交互
@UxForm(grid = 3)
@UxDetail(grid = 3)
@Model.model(Employee.MODEL_MODEL)
@Model(displayName = "标品-员工", labelFields = "name")
@Model.Advanced(index = {"code", "departmentCode"})
public class Employee extends IdModel {

    public static final String MODEL_MODEL = "hr.simple.Employee";

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field.String
    @Field(displayName = "姓名", required = true)
    private String name;

    @UxTableSearch.FieldWidget(@UxWidget())
    @Field.String
    @Field(displayName = "工号", required = true)
    private String code;

    /*******这是一对定义,数据库中只会存corporationCode字段，corporation主要是为了页面交互************/
    @Field.many2one
    @Field.Relation(relationFields = {"corporationCode"}, referenceFields = {"code"})
    @Field(displayName = "公司", required = true)
    private Corporation corporation;

    @Field.String
    @Field(displayName = "公司编码", invisible = true)
    private String corporationCode;

    @Field.many2one
    @Field.Relation(relationFields = {"departmentCode"}, referenceFields = {"code"}, domain = "corporationCode==${activeRecord.corporation.code}")
    @Field(displayName = "部门", required = true)
    private Department department;

    @Field.String
    @Field(displayName = "部门编码", invisible = true)
    private String departmentCode;

    // **********************数据字典表达方式1（枚举方式）： 枚举的方式表达数据字典******************************************************************************
    // **********************数据字典表达方式2（可维护的数据表）：用数据表维护的数据作为数据字典 @see：pro.shushi.pamirs.hr.api.model.biz.ProjectInfo.ditProjectType
    @Field.Enum
    @Field(displayName = "枚举职级", required = true)
    private EmployeeLevelEnum level;

    @Field.many2one
    @Field.Relation(relationFields = "positionCode", referenceFields = "code", domain = "departmentCode==${activeRecord.department.code}")
    @Field(displayName = "主岗位", summary = "主岗位从当前部门下的岗位列表中选择", required = true)
    private Position position;

    @Field.String
    @Field(displayName = "主岗位编码", invisible = true)
    private String positionCode;

    @Field.Enum
    @Field(displayName = "性别", required = true)
    private SimpleGenderEnum gender;

    @Field.Enum
    @Field(displayName = "员工状态", required = true)
    private HrEmployeeStatusEnum employeeStatus;

    @Field.String
    @Field(displayName = "联系电话")
    private String contactPhone;

    // 关系字段参考：https://doc.oinone.top/oio4/9240.html
    @Field.many2one
    @Field.Relation(relationFields = "districtCode", referenceFields = "code")
    @Field(displayName = "住址", summary = "员工住址"/**, required = true**/)
    private ResourceDistrict district;

    @Field.String
    @Field(displayName = "地区编码", invisible = true)
    private String districtCode;

    @UxForm.FieldWidget(@UxWidget(span = 2))
    @UxDetail.FieldWidget(@UxWidget(span = 2))
    @Field.String
    @Field(displayName = "详细地址")
    private String detailAddress;

    @Field.Date(type = DateTypeEnum.DATE, format = DateFormatEnum.DATE)
    @Field(displayName = "入职日期", required = true)
    private Date entryDate;

    @Field.Date(type = DateTypeEnum.DATE, format = DateFormatEnum.DATE)
    @Field(displayName = "生日", required = true)
    private Date birthday;

    @Field.String
    @Field(displayName = "员工标签", multi = true, serialize = COMMA)
    private List<String> labels;

    // 关系字段参考：https://doc.oinone.top/oio4/9240.html
    @Field.many2many(throughClass = EmployeeRelPosition.class, relationFields = {"employeeCode"}, referenceFields = {"positionCode"})
    @Field.Relation(relationFields = {"code"}, referenceFields = {"code"})
    @Field(displayName = "兼职岗位")
    private List<Position> extraPositions;

}
